1 <?php include ( "../inc/connect.inc.php" ); ?>
2 <?php
3
4 ob_start();
5 session_start();
6 if (!isset($_SESSION['admin_login'])) {
7 $user = "";
8 header("location: login.php?ono=".$epid."");
9 }
10 else {
11 if (isset($_REQUEST['epid'])) {
12
13 $epid = mysql_real_escape_string($_REQUEST['epid']);
14 }else {
15 header('location: index.php');
16 }
17 $user = $_SESSION['admin_login'];
18 $result = mysql_query("SELECT * FROM admin WHERE id='$user'");
19 $get_user_email = mysql_fetch_assoc($result);
20 $uname_db = $get_user_email['firstName'];
21
22 }
23 $getposts = mysql_query("SELECT * FROM products WHERE id ='$epid'") or die(mysql_error());
24 if (mysql_num_rows($getposts)) {
25 $row = mysql_fetch_assoc($getposts);
26 $id = $row['id'];
27 $pName = $row['pName'];
28 $price = $row['price'];
29 $description = $row['description'];
30 $picture = $row['picture'];
31 $item = $row['item'];
32 $itemu = ucwords($row['item']);
33 $type = $row['type'];
34 $typeu = ucwords($row['type']);
35 $category = $row['category'];
36 $categoryu = ucwords($row['category']);
37 $code = $row['pCode'];
38 $available =$row['available'];
39 }
40
41 //update product
42 if (isset($_POST['updatepro'])) {
43 $pname = $_POST['pname'];
44 $price = $_POST['price'];
45 $available = $_POST['available'];
46 $category = $_POST['category'];
47 $type = $_POST['type'];
48 $item = $_POST['item'];
49 $pCode = $_POST['code'];
50 //triming name
51 $_POST['pname'] = trim($_POST['pname']);
52
53 if($result = mysql_query("UPDATE products SET pName='$_POST[pname]',price='$_POST[price]',description='$_POST[descri]',available='$_POST[available]',category='$_POST[category]',type='$_POST[type]',item='$_POST[item]',pCode='$_POST[code]' WHERE id='$epid'")){
54 header("Location: editproduct.php?epid=".$epid."");
55
56 }else {
57 echo "no changed";
58 }
59 }
60 if (isset($_POST['updatepic'])) {
61
62 if($_FILES['profilepic'] == ""){
63
64 echo "not changed";
65 }else {
66 //finding file extention
67 $profile_pic_name = @$_FILES['profilepic']['name'];
68 $file_basename = substr($profile_pic_name, 0, strripos($profile_pic_name, '.'));
69 $file_ext = substr($profile_pic_name, strripos($profile_pic_name, '.'));
70
71 if (((@$_FILES['profilepic']['type']=='image/jpeg') || (@$_FILES['profilepic']['type']=='image/png') || (@$_FILES['profilepic']['type']=='image/jpg') || (@$_FILES['profilepic']['type']=='image/gif')) && (@$_FILES['profilepic']['size'] < 1000000)) {
72
73 $item = $item;
74 if (file_exists("../image/product/$item")) {
75 //nothing
76 }else {
77 mkdir("../image/product/$item");
78 }
79
80
81 $filename = strtotime(date('Y-m-d H:i:s')).$file_ext;
82
83 if (file_exists("../image/product/$item/".$filename)) {
84 echo @$_FILES["profilepic"]["name"]."Already exists";
85 }else {
86 if(move_uploaded_file(@$_FILES["profilepic"]["tmp_name"], "../image/product/$item/".$filename)){
87 $photos = $filename;
88 if($result = mysql_query("UPDATE products SET picture='$photos' WHERE id='$epid'")){
89
90 $delete_file = unlink("../image/product/$item/".$picture);
91 header("Location: editproduct.php?epid=".$epid."");
92 }else {
93 echo "Wrong!";
94 }
95 }else {
96 echo "Something Worng on upload!!!";
97 }
98 //echo "Uploaded and stored in: userdata/profile_pics/$item/".@$_FILES["profilepic"]["name"];
99
100
101 }
102 }
103 else {
104 $error_message = "Choose a picture!";
105 }
106
107 }
108 }
109
110
111
112 if (isset($_POST['delprod'])) {
113 //triming name
114 $getposts1 = mysql_query("SELECT pid FROM orders WHERE pid='$epid'") or die(mysql_error());
115 if ($ttl = mysql_num_rows($getposts1)) {
116 $error_message = "You can not delete this product.<br>Someone ordered this.";
117 }
118 else {
119 if(mysql_query("DELETE FROM products WHERE id='$epid'")){
120 header('location: orders.php');
121 }
122 }
123 }
124
125 $search_value = "";
126
127 ?>
128
129 <!DOCTYPE html>
130 <html>
131 <head>
132 <title>SAREE</title>
133 <link rel="stylesheet" type="text/css" href="../css/style.css">
134 <meta name="viewport" content="width=device-width, initial-scale=1">
135 </head>
136 <body style="background-image: url(../image/homebackgrndimg1.png);">
137 <div class="homepageheader">
138 <div class="signinButton loginButton">
139 <div class="uiloginbutton signinButton loginButton" style="margin-right: 40px;">
140 <?php
141 if ($user!="") {
142 echo '<a style="text-decoration: none;color: #fff;" href="logout.php">LOG OUT</a>';
143 }
144 ?>
145
146 </div>
147 <div class="uiloginbutton signinButton loginButton">
148 <?php
149 if ($user!="") {
150 echo '<a style="text-decoration: none;color: #fff;" href="login.php">Hi '.$uname_db.'</a>';
151 }
152 else {
153 echo '<a style="text-decoration: none;color: #fff;" href="login.php">LOG IN</a>';
154 }
155 ?>
156 </div>
157 </div>
158 <div style="float: left; margin: 5px 0px 0px 23px;">
159 <a href="index.php">
160 <img style=" height: 75px; width: 130px;" src="../image/ebuybdlogo.png">
161 </a>
162 </div>
163 <div id="srcheader">
164 <form id="newsearch" method="get" action="search.php">
165 <?php
166 echo '<input type="text" class="srctextinput" name="keywords" size="21" maxlength="120" placeholder="Search Here..." value="'.$search_value.'"><input type="submit" value="search" class="srcbutton" >';
167 ?>
168 </form>
169 <div class="srcclear"></div>
170 </div>
171 </div>
172 <div class="categolis">
173 <table>
174 <tr>
175 <th>
176 <a href="index.php" style="text-decoration: none;color: #fff;padding: 4px 12px;background-color: #c7587e;border-radius: 12px;">Home</a>
177 </th>
178 <th><a href="addproduct.php" style="text-decoration: none;color: #ddd;padding: 4px 12px;background-color: #c7587e;border-radius: 12px;">Add Product</a></th>
179 <th><a href="newadmin.php" style="text-decoration: none;color: #ddd;padding: 4px 12px;background-color: #c7587e;border-radius: 12px;">New Admin</a></th>
180 <th><a href="allproducts.php" style="text-decoration: none;color: #ddd;padding: 4px 12px;background-color: #c7587e;border-radius: 12px;">All Products</a></th>
181 <th><a href="orders.php" style="text-decoration: none;color: #ddd;padding: 4px 12px;background-color: #c7587e;border-radius: 12px;">Orders</a></th>
182 </tr>
183 </table>
184 </div>
185 <div class="holecontainer" style=" padding-top: 20px; padding: 0 20%">
186 <div class="container signupform_content ">
187 <div>
188
189 <h2 style="padding-bottom: 20px;">Edit Product Info</h2>
190 <div style="float: right;">
191 <?php
192 echo '
193 <div class="">
194 <div class="signupform_text"></div>
195 <div>
196 <form action="" method="POST" class="registration">
197 <div class="signup_form">
198 <div>
199 <td >
200 <input name="pname" id="first_name" placeholder="Product Name" required="required" class="first_name signupbox" type="text" size="30" value="'.$pName.'" >
201 </td>
202 </div>
203 <div>
204 <td >
205 <input name="price" id="last_name" placeholder="Price" required="required" class="last_name signupbox" type="text" size="30" value="'.$price.'" >
206 </td>
207 </div>
208 <div>
209 <td>
210 <input name="available" placeholder="Available Quantity" required="required" class="email signupbox" type="text" size="30" value="'.$available.'">
211 </td>
212 </div>
213 <div>
214 <td >
215 <input name="descri" id="first_name" placeholder="Description" required="required" class="first_name signupbox" type="text" size="30" value="'.$description.'" >
216 </td>
217 </div>
218 <div>
219 <td>
220 <select name="category" required="required" style=" font-size: 20px;
221 font-style: italic;margin-bottom: 3px;margin-top: 0px;padding: 14px;line-height: 25px;border-radius: 4px;border: 1px solid #169E8F;color: #169E8F;margin-left: 0;width: 300px;background-color: transparent;" class="">
222 <option selected value="'.$category.'">'.$categoryu.'</option>
223 <option value="women">Women</option>
224 </select>
225 </td>
226 </div>
227 <div>
228 <select name="type" required="required" style=" font-size: 20px;
229 font-style: italic;margin-bottom: 3px;margin-top: 0px;padding: 14px;line-height: 25px;border-radius: 4px;border: 1px solid #169E8F;color: #169E8F;margin-left: 0;width: 300px;background-color: transparent;" class="">
230 <option selected value="'.$type.'">'.$typeu.'</option>
231 <option value="clothing">Clothing</option>
232 <option value="other">Other</option>
233 </select>
234 </div>
235 <div>
236 <td>
237 <select name="item" required="required" style=" font-size: 20px;
238 font-style: italic;margin-bottom: 3px;margin-top: 0px;padding: 14px;line-height: 25px;border-radius: 4px;border: 1px solid #169E8F;color: #169E8F;margin-left: 0;width: 300px;background-color: transparent;" class="">
239 <option selected value="'.$item.'">'.$itemu.'</option>
240 <option value="saree">Saree</option>
241 <option value="ornament">Ornaments</option>
242 <option value="watch">Watch</option>
243 <option value="tshirt">T-Shirt</option>
244 <option value="hijab">Hijab</option>
245 <option value="perfume">Perfume</option>
246 <option value="footwear">Footwear</option>
247 <option value="toiletry">Toiletry</option>
248 <option value="Other">Other</option>
249 </select>
250 </td>
251 </div>
252 <div>
253 <td>
254 <input name="code" id="password-1" required="required" placeholder="Code" class="password signupbox " type="text" size="30" value="'.$code.'">
255 </td>
256 </div>
257 <div>
258 <input name="updatepro" class="uisignupbutton signupbutton" type="submit" value="Update Product">
259 </div>
260 <div>
261 <input name="delprod" class="uisignupbutton signupbutton" type="submit" value="Delete This Product">
262 </div>
263 <div class="signup_error_msg">
264 <?php
265 if (isset($error_message)) {echo $error_message;}
266
267 ?>
268 </div>
269 </div>
270 </form>
271 </div>
272 </div>
273
274 ';
275 if(isset($success_message)) {echo $success_message;}
276
277 ?>
278
279 </div>
280 </div>
281 </div>
282 <div style="float: left;">
283 <div>
284 <?php
285 echo '
286 <ul style="float: left;">
287 <li style="float: left; padding: 0px 25px 25px 25px;">
288 <div class="home-prodlist-img prodlist-img">';
289 if (file_exists('../image/product/'.$item.'/'.$picture.'')){
290 echo '<img src="../image/product/'.$item.'/'.$picture.'" class="home-prodlist-imgi">';
291 }else {
292 echo '
293 <div class="home-prodlist-imgi" style="text-align: center; padding: 0 0 6px 0;">No Image Found!</div>';
294 } echo '
295
296 </div>
297 </li>
298 <li>
299 <form action="" method="POST" class="registration" enctype="multipart/form-data">
300 <div class="signup_form">
301 <div>
302 <td>
303 <input name="profilepic" style="width: 115px;" class="password signupbox" type="file" value="Add Picture">
304 </td>
305 </div>
306 <div>
307 <input name="updatepic" style="width: 144px;" class="uisignupbutton signupbutton" type="submit" value="Change Picture">
308 </div>
309 <div class="signup_error_msg">';
310 if(isset($error_message)) {echo $error_message;}
311 ' </div>
312 </div>
313 </form>
314 </li>
315 </ul>
316 ';
317 ?>
318 </div>
319
320 </div>
321 </div>
322 </body>
323 </html>